namespace Asmex.FileViewer
{
    using Asmex.ObjViewer;
    using System;

    public class Relocation
    {
        private int _offs;
        private int _type;

        public Relocation(ushort n)
        {
            this._type = (n & 0xf000) >> 12;
            this._offs = n & 0xfff;
        }

        public override string ToString()
        {
            return (this._offs.ToString("X8") + " " + this.TypeName);
        }

        [ObjViewer(Hex=true)]
        public int Offset
        {
            get
            {
                return this._offs;
            }
        }

        public int Type
        {
            get
            {
                return this._type;
            }
        }

        public string TypeName
        {
            get
            {
                switch (this._type)
                {
                    case 0:
                        return "Absolute";

                    case 1:
                        return "High";

                    case 2:
                        return "Low";

                    case 3:
                        return "HighLow";

                    case 4:
                        return "HighAdj";

                    case 5:
                        return "Mips Jump";

                    case 6:
                        return "Section";

                    case 7:
                        return "Rel32";

                    case 9:
                        return "Mips Jump 16";

                    case 10:
                        return "Dir64";

                    case 11:
                        return "High32Adj";
                }
                return "Unknown";
            }
        }
    }
}
